/**
 * @param {number[]} code
 * @param {number} k
 * @return {number[]}
 */
var decrypt = function (code, k) {
  // if (k === 0) {
  //   return new Array(code.length).fill(0)
  // }
  let l = code.length;
  let res = [];
  for (let i = 0; i < l; i++) {
    let sum = 0;
    let j = k > 0 ? 1 : k;
    temp = k > 0 ? k : -1
    for (; j <= temp; j++) {
      if (k > 0)
        sum += code[(i + j) % l]
      else
        sum += code[(l + j + i) % l]
    }
    res.push(sum);
  }
  return res;
};
console.log(decrypt([1, 2, 3], 0));
console.log(decrypt([5, 7, 1, 4], 3));
console.log(decrypt([2, 4, 9, 3], -2));